package leading;

public class SingletonTest {
	private static SingletonTest instance = null;
	private int counter = 0;
	public static void main(String[] args) {
		System.out.println(SingletonTest.getInstance());
		System.out.println(SingletonTest.getInstance());
	}
	private SingletonTest(){
	}
	public synchronized static SingletonTest getInstance(){
		if(instance == null){
			System.out.println("新建了一个实例");
			instance = new SingletonTest();
		}else{
			System.out.println("用了之前的实例");
		}
		return  instance;
	}
	
	private int counter(){
		counter += 1;
		return counter;
	}
	
	
	/**
	 * private static final SingletonTest instance = new SingletonTest();
	 * private SingletonTest(){
	 * }
	 * public static SingletonTest getInstance(){
	 *	return instance; 
	 * }
	 * 
	 */
}
